/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddList.java
 *
 * Created on Dec 6, 2010, 10:17:53 PM
 */
package penny.downloadmanager.view.add;

import ca.odell.glazedlists.swing.EventListModel;
import penny.downloadmanager.control.AddDialogControl;
import penny.downloadmanager.model.gui.AddDialogModel;
import java.net.URL;

/**
 *
 * @author john
 */
public class AddList extends javax.swing.JPanel {

    private AddDialogModel addModel;

    AddList(AddDialogModel addModel) {
        this.addModel = addModel;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        delimGroup = new javax.swing.ButtonGroup();
        addDialogModel1 = addModel;
        addFile = new javax.swing.JTextField();
        browse = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        urlList = new javax.swing.JList();
        whiteParse = new javax.swing.JRadioButton();
        srcParse = new javax.swing.JRadioButton();
        parse = new javax.swing.JButton();

        setName("Form"); // NOI18N

        addFile.setName("addFile"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, addDialogModel1, org.jdesktop.beansbinding.ELProperty.create("${listFileName}"), addFile, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        browse.setText("Browse..."); // NOI18N
        browse.setName("browse"); // NOI18N

        jLabel1.setText("List:"); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        urlList.setModel(new EventListModel<URL>(addModel.getUrls()));
        urlList.setName("urlList"); // NOI18N
        jScrollPane1.setViewportView(urlList);

        delimGroup.add(whiteParse);
        whiteParse.setText("whitespace/comma"); // NOI18N
        whiteParse.setName("whiteParse"); // NOI18N

        delimGroup.add(srcParse);
        srcParse.setText("href/src"); // NOI18N
        srcParse.setEnabled(false);
        srcParse.setName("srcParse"); // NOI18N

        parse.setText("Parse"); // NOI18N
        parse.setName("parse"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(addFile, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(whiteParse)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(srcParse)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(browse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(parse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browse)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(whiteParse)
                    .addComponent(parse)
                    .addComponent(srcParse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private penny.downloadmanager.model.gui.AddDialogModel addDialogModel1;
    private javax.swing.JTextField addFile;
    private javax.swing.JButton browse;
    private javax.swing.ButtonGroup delimGroup;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton parse;
    private javax.swing.JRadioButton srcParse;
    private javax.swing.JList urlList;
    private javax.swing.JRadioButton whiteParse;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    void registerController(AddDialogControl addController) {
        browse.addActionListener(addController);
        browse.setActionCommand(AddDialogControl.COM_BROWSE);
        whiteParse.addActionListener(addController);
        whiteParse.setActionCommand(AddDialogControl.COM_WHITESPACE);
        srcParse.addActionListener(addController);
        srcParse.setActionCommand(AddDialogControl.COM_SRC);
        parse.addActionListener(addController);
        parse.setActionCommand(AddDialogControl.COM_PARSE);
        delimGroup.setSelected(whiteParse.getModel(), true);
        addModel.setListType(delimGroup.getSelection().getActionCommand());
    }
}
